06. Drawing Custom Views
21 4 AAK Create Custom View SC-Slide Part 2
Android Developer Documentation
- Custom Components
- How Android Draws Views
- [onMeasure()](https://developer.android.com/reference/android/view/View.html#onMeasure%28int, int%29)
- [onSizeChanged()](https://developer.android.com/reference/android/view/View.html#onSizeChanged%28int, int, int, int%29)
- onDraw()
- Canvas
- Paint
- [rawText()](https://developer.android.com/reference/android/graphics/Canvas.html#drawText%28char[], int, int, float, float, android.graphics.Paint%29)
- setTypeface()
- setColor()
- [drawRect()](https://developer.android.com/reference/android/graphics/Canvas.html#drawRect%28android.graphics.Rect, android.graphics.Paint%29)
- [drawOval()](https://developer.android.com/reference/android/graphics/Canvas.html#drawOval%28android.graphics.RectF, android.graphics.Paint%29)
- [drawArc()](https://developer.android.com/reference/android/graphics/Canvas.html#drawArc%28android.graphics.RectF, float, float, boolean, android.graphics.Paint%29)
- [drawBitmap()](https://developer.android.com/reference/android/graphics/Canvas.html#drawBitmap%28android.graphics.Bitmap, android.graphics.Matrix, android.graphics.Paint%29)
- setStyle()
- invalidate()
Reflect
QUESTION:
Why do you need to override onSizeChanged()?
ANSWER:
When onSizeChanged() is called for the first time, the correct size for the canvas has been calculated and is now available for use.
Reflect
QUESTION:
What happens if you get the size of the canvas in onCreate()?
ANSWER:
In onCreate(), the size of the canvas is returned as 0,0 because its size has not been determined yet.